﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using StoryTeller.Domain.Exceptions;

namespace StoryTellerSite.Models
{
    public enum AlertType
    {
        Error = 0,
        Success = 1,
        Warning = 2
    }

    public class MessageModel
    {
        public MessageModel(FriendlyErrorMessageException ex)
        {            
            this.Add(ex.Message, AlertType.Error);
        }

        public MessageModel(ValidationMessagesException ex)
        {
            this.Add(ex.Messages, AlertType.Warning);            
        }

        private AlertType alert;

        public AlertType Alert
        {
            get { return alert; }
        }

        public List<String> Text { get; set; }

        public void Add(String Message, AlertType MessageType)
        {
            if (this.Text == null)
                this.Text = new List<string>();

            this.Text.Add(Message);
            this.alert = MessageType;
        }

        public void Add(ICollection<String> Messages, AlertType MessageType)
        {
            if (this.Text == null)
                this.Text = new List<string>();

            this.Text.AddRange(Messages);
            this.alert = MessageType;
        }

        public string FirstOrDefault()
        {
            return this.Text.FirstOrDefault();
        }

        public int Count()
        {
            return this.Text != null ? this.Text.Count : 0;
        }

    }
}